package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/user/setmeal")
@Slf4j
@RestController("userSetmealController")
@Api(tags = "套餐相关接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 根据种类id查询套餐
     * @param categoryId
     * @return
     */
    @ApiOperation(value = "根据种类id查询套餐")
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache", key = "#categoryId")
    public Result<List<Setmeal>> list(Integer categoryId) {
        log.info("根据种类id：{}查询套餐", categoryId);

        List<Setmeal> list = setmealService.selectByCategoryId(categoryId);
        return Result.success(list);
    }


    /**
     * 通过套餐id查询菜品item
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> selectDishBySetmealId(@PathVariable Integer id) {
        log.info("根据套餐id：{}查询菜品item", id);

        List<DishItemVO> list = setmealService.selectDishBySetmealId(id);
        return Result.success(list);
    }

}
